<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
				<a name="cmtArea"></a>
            	<div class="ct_detail_box ct_detail_box_f">
                	<div id='cmtContent'></div>
                    <div class="ct_detail_page">
                        <a href="javascript:_moveNextCmt();" class="detail_page_next"></a>
                        <span id='showCmtPage'  style="display: none;"></span>
                        <a href="javascript:_movePreCmt();" class="detail_page_pre"></a>
                    </div>
                    <form id="cmtForm">                    
                    <div class="ct_detail_answer">                    	
                    	<textarea name="commentInfo" id="commentInfo"></textarea>                        
                        <a class="float_rg ct_detail_cm" href="javascript:doCmt();">评论</a>
                    </div> 
                    </form>
                </div>
<script type="text/javascript">
<!--
var cmtPageSize=8;//评论页面大小
var cmtCurPage=1;//当前页面
var cmtCount=0;//评论总数
var cmtPageCount=0;//页面总数
//移至上一页
function _movePreCmt(){	
	if(cmtCurPage>1){
		--cmtCurPage;	
	}else{
		cmtCurPage=1;
	}
	doCmtQuery();    
}
//移至下一页
function _moveNextCmt(){
	if(cmtCurPage<cmtPageCount){
		++cmtCurPage;	
	}else{
		cmtCurPage=cmtPageCount
	}	
	doCmtQuery();
}
//评论
function doCmt(){	
	$.post("${ctx}/frontCmt!add.action?goodsId=${data.goodsId}", $("#cmtForm").serialize() ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				$('#commentInfo').val('');
				doCmtQuery();
			}else if (json.code==3) {	
				alert('请先登录！');
			}else{
				alert('评论失败！');
			}
		}	
	);
}
//查询评论列表
function doCmtQuery(){
	var url="${ctx}/frontCmt!getList.action";
	$.post(url, "q_goodsId=${data.goodsId}&page="+cmtCurPage+"&pageSize="+cmtPageSize ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				cmtCount=json.count;
				cmtPageCount=Math.floor(cmtCount/cmtPageSize)+(cmtCount%cmtPageSize==0?0:1);	
				$('#showCmtPage').html(cmtCurPage+"/"+cmtPageCount);
				createCmtNotes(json.info);				
			}else{
				alert('查询商品列表失败！');
			}
		}	
	);
}
//创建商品列表数据
function createCmtNotes(objs){		
	var c="";
	for(var i=0;i<objs.length;i++){
		var obj=objs[i];		
		c+='<div class="ct_detail_meg">';
		c+='    <div class="ct_detail_m_pic">';
		c+='        <a title="'+obj.account+'"><img src="front/images/head.jpg" width="40" height="40" /></a>';
		c+='    </div>';
		c+='    <div class="ct_detail_name">';
		c+='        <p><strong>'+obj.account+'</strong></p>';
		c+='        <p>'+obj.commentInfo+'</p>';
		c+='    </div>';
		c+='    <div class="ct_detail_mg_time">'+formatDate(obj.createTime)+'</div>';
		c+='</div>';		
	}	
	$('#cmtContent').html(c);
}
//格式化日期：yyyy-MM-dd HH:mm:ss
function formatDate(time){
	var date=new Date(time);
	var m = date.getMonth()+1;
	var d = date.getDate();
	var H=date.getHours();
	var n=date.getMinutes();
	var s=date.getSeconds();
	return date.getFullYear()+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d)+" "+(H<10?('0'+H):H)+":"+(n<10?('0'+n):n)+":"+(s<10?('0'+s):s);
}
//-->
</script>